package com.glory.dgcpcpda.adapter;

import android.widget.CheckBox;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.dgcpcpda.R;
import com.glory.dgcpcpda.entity.EdcSetBinEntity;
import com.glory.dgcpcpda.entity.SimpleEntity;

import java.util.ArrayList;
import java.util.List;

public class FTBinListAdapter extends BaseQuickAdapter<SimpleEntity.MantissaLotBinData, BaseViewHolder> {

    private List<SimpleEntity.MantissaLotBinData> mList;
    private int mIndex = -1;

    public FTBinListAdapter(@Nullable List<SimpleEntity.MantissaLotBinData> data) {
        super(R.layout.adapter_ft_bin,data);
        mList = new ArrayList<>();
    }

    @Override
    protected void convert(BaseViewHolder helper, SimpleEntity.MantissaLotBinData item) {
        helper.setText(R.id.tvName,item.getBINNAME())
                .setText(R.id.tvDesc,item.getBINDESC())
                .setText(R.id.tvQTY,String.valueOf(item.getMAINQTY()));

        CheckBox checkBox = helper.getView(R.id.checkbox);
        checkBox.setChecked(false);
        checkBox.setOnClickListener(view -> {
            if (mIndex == -1){
                mIndex = helper.getAdapterPosition();
                mList.add(item);
            }else if (mIndex == helper.getAdapterPosition()){
                mIndex = -1;
                mList.clear();
            }else if (mIndex != helper.getAdapterPosition()){
                notifyItemChanged(mIndex);
                mList.clear();
                mList.add(item);
                mIndex = helper.getAdapterPosition();
            }

        });
    }

    public List<SimpleEntity.MantissaLotBinData> getSelectorData(){
        return mList;
    }
}
